/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.opt.transco.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Transformer;
import org.springframework.stereotype.Component;

import fr.generali.accueilclient.opt.transco.builder.DTOTranscoBuilder;
import fr.generali.accueilclient.opt.transco.om.ITransco;
import fr.generali.accueilclient.opt.transco.om.ITypeTransco;
import fr.generali.relationclient.marketing.opt.detailtransco.DtoTransco;
import fr.generali.relationclient.marketing.opt.detailtransco.DtoTypeTransco;
import fr.generali.relationclient.marketing.opt.detailtransco.builder.DtoTypeTranscoBuilder;

/**
 * @author Holmes Kelly
 */

@Component("listeTranscoMapper")
public class ListeTranscoMapper {

    /**
     * @param typeTransco type transco
     * @return DtoTypeTransco
     */
    public DtoTypeTransco mapperTypeTransco2DtoTypeTransco(ITypeTransco typeTransco) {

        DtoTypeTransco dtoTypeTransco = null;

        if (typeTransco != null) {

            dtoTypeTransco =
                            DtoTypeTranscoBuilder.dtoTypeTransco().buildDossier(typeTransco.getDossier())
                                            .buildTransco(typeTransco.getTransco()).build();
        }

        return dtoTypeTransco;
    }

    /**
     * @param listDtoTransco list DtoTransco
     * @return list ITransco
     */
    public List<ITransco> mapperListerTransco2ListITransco(List<DtoTransco> listDtoTransco) {

        List<ITransco> listTransco = null;

        if (CollectionUtils.isNotEmpty(listDtoTransco)) {

            listTransco = new ArrayList<ITransco>();

            CollectionUtils.collect(listDtoTransco, getTransformerDtoTransco2ITransco(), listTransco);
        }

        return listTransco;
    }

    /**
     * @return transformer DtoTransco -> ITransco
     */
    private Transformer getTransformerDtoTransco2ITransco() {

        Transformer transformer = new Transformer() {

            public Object transform(Object input) {

                DtoTransco dtoTransco = DtoTransco.class.cast(input);

                ITransco transco =
                                DTOTranscoBuilder.dTOTransco().buildIdentifiant(dtoTransco.getIdentifiant())
                                                .buildLibelle(dtoTransco.getLibelle())
                                                .buildTypeDossier(dtoTransco.getTypeDossier())
                                                .buildTypeTransco(dtoTransco.getTypeTransco()).build();

                return transco;
            }
        };

        return transformer;
    }
}
